package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2024/10/1 10:03
 * @apiNote
 */

public class Test00091NumDecodings {
    public int numDecodings(String s) {int n = s.length();
        int[] dp = new int[n+1];
        dp[0] = 1;
        for(int i = 1;i<=n;i++){
            if(s.charAt(i-1) != '0'){
                dp[i] = dp[i-1];
            }
            if(i>1&& s.charAt(i-2) != '0'
                    && (Integer.parseInt(s.substring(i - 2, i)) >0 &&  Integer.parseInt(s.substring(i - 2, i)) <= 26)){
                dp[i] += dp[i-2];
            }
        }
        return dp[n];
    }


}
